


def decode_mutf8(bytes_data):
    # 简单解码
    return bytes_data.decode(encoding='utf-8')
    # if len(bytes_data) > 0:
    #     str1 = []
    #     for i in range(0, len(bytes_data)):
    #         if bytes_data[i] > 128:
    #             newInt = bytes_data[i] - 256
    #         else:
    #             newInt = bytes_data[i]
    #         str1.append(newInt)
    #     jpype.startJVM()
    #     python_bytes = jpype.JArray(jpype.JByte)(str1).tolist()
    #     ns  = python_bytes.encode().decode('utf-8')
    #     print(ns)
    #
    #     jpype.shutdownJVM()
    #
    # def two_bytes_to_char(b1, b2):
    #     # MUTF-8 中特殊的两个字节序列到字符的映射
    #     # 这里只处理了最常见的几个字符，完整映射需要更多逻辑
    #     if b1 == 0xC0 and b2 == 0x80:
    #         return '\u00C0'  # 对应于 Latin-1 中的 À
    #     if b1 == 0xC1 and b2 == 0x80:
    #         return '\u00C1'  # 对应于 Latin-1 中的 Á
    #     # ... 其他映射 ...
    #     raise ValueError("Unsupported two-byte sequence")
    #
    # def decode_utf8_char(b1, b2, b3):
    #     # 标准 UTF-8 三字节字符解码
    #     char_code = (b1 & 0x0F) << 12 | (b2 & 0x3F) << 6 | (b3 & 0x3F)
    #     return chr(char_code)
    #
    # result = []
    # i = 0
    # while i < len(bytes_data):
    #     b = bytes_data[i]
    #     if b < 0x80:  # ASCII 字符
    #         result.append(chr(b))
    #         i += 1
    #     elif (b >> 5) == 0x06:  # 两字节 UTF-8 字符
    #         if i + 1 >= len(bytes_data):
    #             raise ValueError("Incomplete two-byte UTF-8 sequence")
    #         b2 = bytes_data[i + 1]
    #         if (b2 & 0xC0) != 0x80:
    #             raise ValueError("Invalid second byte in two-byte UTF-8 sequence")
    #         result.append(chr(((b & 0x1F) << 6) | (b2 & 0x3F)))
    #         i += 2
    #     elif (b >> 4) == 0x0E:  # MUTF-8 中特殊的两字节序列
    #         if i + 1 >= len(bytes_data):
    #             raise ValueError("Incomplete two-byte MUTF-8 sequence")
    #         b2 = bytes_data[i + 1]
    #         if (b2 & 0xC0) != 0x80:
    #             raise ValueError("Invalid second byte in two-byte MUTF-8 sequence")
    #         result.append(two_bytes_to_char(b, b2))
    #         i += 2
    #     elif (b >> 4) == 0x0F:  # 三字节 UTF-8 字符
    #         if i + 2 >= len(bytes_data):
    #             raise ValueError("Incomplete three-byte UTF-8 sequence")
    #         b2 = bytes_data[i + 1]
    #         b3 = bytes_data[i + 2]
    #         if (b2 & 0xC0) != 0x80 or (b3 & 0xC0) != 0x80:
    #             raise ValueError("Invalid second or third byte in three-byte UTF-8 sequence")
    #         result.append(decode_utf8_char(b, b2, b3))
    #         i += 3
    #     else:
    #         raise ValueError(f"Unsupported first byte: {b:02x}")
    #
    # return ''.join(result)
